package com.jicheng.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jicheng.Utils.ResultMess;
import com.jicheng.dto.data.IntegrityListParams;
import com.jicheng.dto.integrity.IntegrityListDto;
import com.jicheng.dto.integrity.IntergrityDetailDto;
import com.jicheng.dto.task.*;
import com.jicheng.ext.dto.PagingResult;
import com.jicheng.service.IInfoQueryService;
import com.jicheng.service.ITaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: InfoQueryController
 * @Description: TODO
 * @author: khz
 * @date: 2020年08月20日 8:33
 */
@Api(tags = "(info-query)信息查询")
@RestController
@RequestMapping(value = "info-query", produces = "application/json;charset=UTF-8")
public class InfoQueryController {
    @Autowired
    IInfoQueryService infoQueryService;

    @Autowired
    ITaskService taskService;
    /**
     * 监督任务查询列表
     *
     * @return
     */
    @ApiOperation(value = "监督任务查询列表")
    @GetMapping("/getTaskList")
    public PagingResult<TaskDto> getTaskList(PagingTaskParams params) {
        PagingResult<TaskDto> result =taskService.getTaskList(params);
        return result;
    }
    /**
     * 查看监督任务详情
     *
     * @return
     */
    @ApiOperation(value = "查看监督任务详情")
    @GetMapping("/getTaskDetail")
    public ResultMess<TaskDetailDto> getTaskDetail(@RequestParam("taskId") String taskId, HttpServletRequest request) {
        TaskDetailDto taskDetail =  taskService.getTaskDetail(taskId,request);
        return new ResultMess(true,"",taskDetail);
    }
    /**
     * 获取任务类型下拉
     *
     * @return
     */
    @ApiOperation(value = "获取任务类型下拉")
    @GetMapping("/getTaskType")
    public List<String> getTaskType() {
        List<String> taskDetail =  taskService.getTaskType();
        return taskDetail;
    }
    /**
     * 获取业务模板下拉
     *
     * @return
     */
    @ApiOperation(value = "获取业务模板下拉")
    @GetMapping("/getTemplateType")
    public List<String> getTemplateType() {
        List<String> list =  taskService.getTemplateType();
        return list;
    }

    /**
     * 业务模板查询列表
     *
     * @return
     */
    @ApiOperation(value = "业务模板查询列表")
    @GetMapping("/getBusTemplateList")
    public PagingResult<TemplateDto> getBusTemplateList(PagingTemplateParams params) {
        PageHelper.startPage(params.getPage(),params.getPageSize());
        List<TemplateDto> list = taskService.getBusTemplateList(params);
        PageInfo pageInfo = new PageInfo<>(list);
        PagingResult result = new PagingResult();
        result.setList(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());
        return result;
    }

    /**
     * 查看业务模板详情
     *
     * @return
     */
    @ApiOperation(value = "查看业务模板详情")
    @GetMapping("/getTemplateDetail")
    public ResultMess<TemplateFileDto> getTemplateDetail(@RequestParam("id") String id, HttpServletRequest request) {
        TemplateFileDto taskDetail =  taskService.getTemplateDetail(id,request);
        return new ResultMess(true,"",taskDetail);
    }


    /**
     * 廉政档案查询列表
     *
     * @return
     */
    @ApiOperation(value = "廉政档案查询列表")
    @GetMapping("/getIntegrityList")
    public PagingResult<IntegrityListDto> getIntegrityList(IntegrityListParams integrityListParams) {
        PageHelper.startPage(integrityListParams.getPage(), integrityListParams.getPageSize());
        List<IntegrityListDto> list = infoQueryService.getIntegrityList(integrityListParams);
        PageInfo pageInfo = new PageInfo<>(list);
        PagingResult result = new PagingResult();
        result.setList(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());
        return result;
    }

    /**
     * 廉政档案详细信息查询
     */
    @ApiOperation(value = "廉政档案详细信息查询")
    @GetMapping("/getIntegritydetail")
    public ResultMess<IntergrityDetailDto> getIntegritydetail(String reportId, String cadreId, String appId) {
        IntergrityDetailDto map = infoQueryService.getIntegritydetail(reportId, cadreId, appId);
        return new ResultMess<IntergrityDetailDto>(true,"",map);
    }

    /**
     * 获取终端用户
     */
    @ApiOperation(value = "获取终端用户")
    @GetMapping("/getAppUser")
    public List<Map> getAppUser() {
        List<Map> list = infoQueryService.getAppUser();
        return list;
    }

    /**
     * 廉政档案-获取所属单位
     */
    @ApiOperation(value = "廉政档案-获取所属单位")
    @GetMapping("/getUnit")
    public List<String> getUnit() {
        List<String> list = infoQueryService.getUnit();
        return list;
    }

    /**
     * 获取期数
     */
    @ApiOperation(value = "获取期数")
    @GetMapping("/getPeriod")
    public List<String> getPeriod() {
        List<String> list = infoQueryService.getPeriod();
        return list;
    }

    /**
     * 获取期数
     */
    @ApiOperation(value = "获取模板库列表")
    @GetMapping("/getTempLibList")
    public PagingResult<TemplateDto> getTempLibList(PagingTemplateParams params) {
        PageHelper.startPage(params.getPage(),params.getPageSize());
        List<TemplateDto> list = infoQueryService.getTempLibList(params);
        PageInfo pageInfo = new PageInfo<>(list);
        PagingResult result = new PagingResult();
        result.setList(pageInfo.getList());
        result.setTotal(pageInfo.getTotal());
        return result;
    }

    /**
     * 查看业务模板库详情
     *
     * @return
     */
    @ApiOperation(value = "查看业务模板库详情")
    @GetMapping("/getTempLibDetail")
    public ResultMess<TemplateFileDto> getTempLibDetail(@RequestParam("id") String id, HttpServletRequest request) {
        TemplateFileDto taskDetail =  infoQueryService.getTempLibDetail(id,request);
        return new ResultMess(true,"",taskDetail);
    }

}
